﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAL
{
    public class PriceSeller
    {
        public static PriceSellerEntity getById(int psId)
        {
            DataRow dr = DbHelper.ExecuteDataRow("p_PriceSeller_getById", psId);
            PriceSellerEntity ps = new PriceSellerEntity();
            if (dr != null)
            {
                ps.PsId = psId;
                ps.CustomerId = Convert.ToInt32(dr["customerId"]);
                ps.InputDt = Convert.ToDateTime(dr["inputDt"]);
                ps.IsUse = Convert.ToBoolean(dr["isUse"]);
                ps.ProductId = Convert.ToInt32(dr["ProductId"]);
                ps.SellerId = Convert.ToInt32(dr["SellerId"]);
                ps.SellerPrice = Convert.ToDecimal(dr["SellerPrice"]);
                ps.Unit = dr["Unit"].ToString();
                
            }
            return ps;
        }

       

        public static void updatePrice(PriceSellerEntity ps)
        {
            DbHelper.ExecuteNonQuery("p_PriceSeller_updatePrice", ps.SellerId, ps.CustomerId, ps.ProductId, ps.SellerPrice, ps.Unit, ps.AdminId, ps.Source, ps.ContactMan, ps.Reason);

        }

        public static void updatePriceV2(PriceSellerEntity ps)
        {
            DbHelper.ExecuteNonQuery("p_PriceSeller_updatePriceV2", ps.SellerId, ps.CustomerId, ps.ProductId, ps.SellerPrice, ps.Unit, ps.AdminId, ps.Source, ps.ContactMan, ps.Reason,ps.BusinessNature);
        }

        public static void updateUseByProduct(int productId)
        {
             DbHelper.ExecuteNonQuery("p_PriceSeller_updateUseByProduct", productId);
        }

        //得到商品，当前供应商列表
        public static DataSet getCurrenSellerPriceByProduct(int productId,string nature)
        {
           return   DbHelper.ExecuteReDataSet("p_PriceSeller_getCurrenSellerPriceByProduct", productId,nature);
        }

        public static DataSet getPriceSellerAmstock(int productId)
        {
            return DbHelper.ExecuteReDataSet("p_priceSeller_amstock", productId);
        }

        public static void sendMsgToManager(int categoryid,int sellerid)
        {
            DbHelper.ExecuteNonQuery("p_PriceSeller_sendMsgToManager", categoryid, sellerid);
        }
    }
}
